package com.zmkj.cn.comm.util;

import cn.hutool.core.date.DateUtil;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class MyDateUtil {

    /**
     * 中文年月日
     */
    public static final String FORMAT_CN_DATE = "yyyy年MM月dd日";

    public static final String FORMAT_CN_ODATE = "yyyy年M月d日";

    public static final String FORMAT_CN_DATE_TIME = "yyyy年MM月dd日 HH:mm:ss";

    public static final String FORMAT_YEAR_OMONTHER_DAY = "yyyy.M.dd";

    public static final String FORMAT_USU = "yyyy-MM-dd HH:mm:ss";

    public static final String FORMAT_YEAR_MONTH_DAY = "yyyy-MM-dd";

    public static final String FORMAT_CONTINUITY = "yyyyMMdd";


    /**
     * 时间格式化
     *
     * @param fromat
     * @param time
     * 
     */
    public static final String getTimeStr(String fromat, Date time) {
        if (time == null) {
            return "";
        }
        SimpleDateFormat st = new SimpleDateFormat(fromat);
        return st.format(time);
    }

    /**
     * 对日期进行加减操作
     *
     * @param date       要进行加减天数的日期
     * @param addOrMinus 对日期加减天数（eg：加一天：1 减一天：-1）
     * 
     */
    public static Date dateAddOrMinus(Date date, Integer addOrMinus) {
        if (addOrMinus == null || "".equals(addOrMinus)) {
            addOrMinus = 0;
        }
        //使用默认时区和语言环境获得一个日历
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.DAY_OF_MONTH, +addOrMinus);
        return cal.getTime();
    }

    /**
     * java 获取 获取某年某月 所有日期（yyyy-mm-dd格式字符串）
     *
     * @param year
     * @param month
     * 
     */
    public static List<String> getMonthFullDay(int year, int month) {

//        SimpleDateFormat dateFormat = new SimpleDateFormat();
        List<String> fullDayList = new ArrayList<>(32);
        // 获得当前日期对象
        Calendar cal = Calendar.getInstance();
        cal.clear();// 清除信息
        cal.set(Calendar.YEAR, year);
        // 1月从0开始
        cal.set(Calendar.MONTH, month - 1);
        // 当月1号
        cal.set(Calendar.DAY_OF_MONTH, 1);
        int count = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        for (int j = 1; j <= count; j++) {
            fullDayList.add(DateUtil.format(cal.getTime(), FORMAT_YEAR_MONTH_DAY));
            cal.add(Calendar.DAY_OF_MONTH, 1);
        }
        return fullDayList;
    }

    public static List<String> getMonthFullDay(Date date) {
        return getMonthFullDay(DateUtil.year(date), DateUtil.month(date) + 1);
    }

    public static boolean isWeekend(String date) throws ParseException {
        Date bdate = DateUtil.parse(date, FORMAT_YEAR_MONTH_DAY);
        Calendar cal = Calendar.getInstance();
        cal.setTime(bdate);
        if(cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY){
            return true;
        } else{
            return false;
        }

    }


}
